import request from '@/utils/http/request'


export interface UserResponse {
  items: UserModel[],
  total: number
}

export interface UserModel {
  id?: string,
  gmtCreate: string,
  gmtModified: string,
  deleted: false,
  username?: string,
  password?: string,
  nickName?: string,
  salt?: null,
  token?: null,
  roleName: string
  remark?: null
}

interface formParams {
  username: string,
  nickName: string,
  password: string
}

interface AssignResponse {
  allRolesList: UserModel[],
  assignRoles: UserModel[]
}

export const getUserList = (page: number, limit: number, username: string) => {
  return request.get<any, UserResponse>(`/admin/acl/user/${page}/${limit}?username=${username}`)
}

export const remove = (id: string) => {
  return request.delete(`/admin/acl/user/remove/${id}`)
}

export const update = (params: UserModel) => {
  return request.put('/admin/acl/user/update', params)
}

export const save = (form: formParams) => {
  return request.post('/admin/acl/user/save', form)
}

export const toAssign = (id: string) => {
  return request.get<any, AssignResponse>(`/admin/acl/user/toAssign/${id}`)
}

export const doAssign = (userId: string, roleId: string) => {
  return request.post(`/admin/acl/user/doAssign?userId=${userId}&roleId=${roleId}`)
}